Skip to content

打开控制台高级 - OpenConsoleEx

函数简介

按窗口句柄打开控制台。type 为 0 时打开插件进程自身控制台;为 1 时在目标窗口所属进程中打开控制台。

接口名称

OpenConsoleEx

DLL调用

c
int32_t OpenConsoleEx(int64_t instance, int64_t hwnd, int32_t type);

参数说明

参数名类型说明
instance长整数型OLAPlug 对象的指针,由 CreateCOLAPlugInterFace 接口生成。
hwnd长整数型目标窗口句柄;type!=0 时用于定位目标进程。
type整数型打开类型,见下表。

type 取值

说明
0软件本身(插件进程)控制台
1目标窗口进程控制台

示例

hwnd + type:0=本进程;1=目标窗口所属进程。

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

int64_t hwnd = 0; // 目标窗口句柄;type=0 时可填 0
int ret = ola.OpenConsoleEx(hwnd, 0); // 本进程
if (ret != 1) {
    return;
}
// type=1:ola.OpenConsoleEx(hwnd, 1); // 在目标进程打开
ola.LogSetTarget(0, 2); // CONSOLE
ola.LogInfo("console ex opened");
csharp
using System;
using OLAPlug;

var ola = new OLAPlugServer();

long hwnd = 0; // 目标窗口句柄
int ret = ola.OpenConsoleEx(hwnd, 0);
if (ret != 1) return;
ola.LogSetTarget(0, 2);
ola.LogInfo("console ex opened");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()

hwnd = 0  # 目标窗口句柄
ret = ola.OpenConsoleEx(hwnd, 0)
if ret != 1:
    raise RuntimeError("OpenConsoleEx failed")
ola.LogSetTarget(0, 2)
ola.LogInfo("console ex opened")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();

long hwnd = 0;
int ret = ola.OpenConsoleEx(hwnd, 0);
if (ret != 1) {
    return;
}
ola.LogSetTarget(0, 2);
ola.LogInfo("console ex opened");
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()

hwnd := int64(0)
ret := ola.OpenConsoleEx(hwnd, 0)
if ret != 1 {
    return
}
ola.LogSetTarget(0, 2)
ola.LogInfo("console ex opened")
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();

let hwnd = 0i64;
let ret = ola.open_console_ex(hwnd, 0);
if ret != 1 {
    return;
}
ola.log_set_target(0, 2);
ola.log_info("console ex opened");
cpp
var ola = com("OlaPlug.OlaSoft")

var hwnd = 0
var ret = ola.OpenConsoleEx(hwnd, 0)
if(ret == 1) {
    ola.LogSetTarget(0, 2)
    ola.LogInfo("console ex opened")
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")

hwnd = 0
ret = ola.OpenConsoleEx(hwnd, 0)
If ret = 1 Then
    ola.LogSetTarget 0, 2
    ola.LogInfo "console ex opened"
End If
text
.局部变量 ola, OLAPlug
.局部变量 ret, 整数型

ola.Create ()

.局部变量 hwnd, 长整数型
hwnd = 0
ret = ola.OpenConsoleEx (hwnd, 0)
.如果真 (ret = 1)
    ola.LogSetTarget (0, 2)
    ola.LogInfo (“console ex opened”)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();

var hwnd = 0;
var ret = ola.OpenConsoleEx(hwnd, 0);
if(ret == 1){
    ola.LogSetTarget(0, 2);
    ola.LogInfo("console ex opened");
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer

长整数 hwnd = 0
整数 ret = ola.OpenConsoleEx(hwnd, 0)
如果真 (ret = 1)
{
    ola.LogSetTarget(0, 2)
    ola.LogInfo("console ex opened")
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

int64_t hwnd = 0;
int32_t ret = ola.OpenConsoleEx(hwnd, 0);
if (ret != 1) {
    return;
}
ola.LogSetTarget(0, 2);
ola.LogInfo("console ex opened");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long logger = 0;

int64_t hwnd = 0;
int ret = OpenConsoleEx(instance, hwnd, 0);
if (ret != 1) {
    return;
}
LogSetTarget(instance, 0, 2);
LogInfo(instance, "console ex opened");
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int OpenConsoleEx(long ola, long hwnd, int type);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogSetTarget(long ola, long loggerHandle, int targetFlags);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogInfo(long ola, string message);

long instance = CreateCOLAPlugInterFace();
long logger = 0;

long hwnd = 0;
int ret = OpenConsoleEx(instance, hwnd, 0);
if (ret != 1) return;
LogSetTarget(instance, 0, 2);
LogInfo(instance, "console ex opened");
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
logger = 0

hwnd = 0
ret = ola.OpenConsoleEx(instance, hwnd, 0)
if ret != 1:
    raise RuntimeError("OpenConsoleEx failed")
ola.LogSetTarget(instance, 0, 2)
ola.LogInfo(instance, b"console ex opened")

返回值

返回值说明
1成功。
0失败。

注意事项

项目说明
CloseConsoleEx使用完毕后建议调用 关闭控制台高级 - CloseConsoleExtype 与打开时一致。